package com.yonyou.pmclouds.plan.processor;

import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.plan.entity.ScheduleItemVO;
import com.yonyou.pmclouds.plan.entity.ScheduleVO;
import com.yonyou.pmclouds.plan.rmiitf.IScheduleItemProcessor;
import org.springframework.stereotype.Component;

/**
 * @Description: 统计按时完成率
 * @Author: zhangzhonghao
 * @Date: 2020-03-15
 */
@Component
public class ScheduleOnTimeCompletionRateProcessor implements IScheduleItemProcessor {

    private int totalFinishCount = 0;

    private int onTimeCount = 0;

    @Override
    public void process(ScheduleVO scheduleVO, ScheduleItemVO rootParentItemVO, ScheduleItemVO parentItemVO, ScheduleItemVO childItemVO) throws BusinessException {
        if (childItemVO.getChildCount() == 0 && childItemVO.getProgressVO() != null &&
                childItemVO.getProgressVO().getProgress() == 100) {
            totalFinishCount++;
            if (childItemVO.getProgressVO().getEndDate() != null &&
                    childItemVO.getProgressVO().getEndDate().before(childItemVO.getPlanEndDate())) {
                onTimeCount++;
            }
        }
    }

    public int getTotalFinishCount() {
        return totalFinishCount;
    }

    public int getOnTimeCount() {
        return onTimeCount;
    }
}
